/**
 * 
 */
package com.base.myproject.client.busi.b2c;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseStoreEvent;
import com.base.myproject.client.busi.BaseStoreListener;
import com.base.myproject.client.busi.HtmlCommandFactory;
import com.base.myproject.client.busi.JDBCModelData;
import com.base.myproject.client.busi.BaseStoreEvent.EventType;
import com.base.myproject.client.busi.b2c.b2cgcodeattr.AttrFactory;
import com.base.myproject.client.busi.b2c.b2cgcodeattr.DetailDesc;
import com.base.myproject.client.busi.b2c.b2cgcodeattr.ImageGroup;
import com.base.myproject.client.busi.b2c.shopping.ShoppingCar;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseImageList;
import com.base.myproject.client.ui.celleditor.BaseCellEditorCB;
import com.base.myproject.client.ui.celleditor.BaseComboBox;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.DataField;
import com.extjs.gxt.ui.client.data.HttpProxy;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.extjs.gxt.ui.client.data.XmlReader;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;

/**
 * //注意商品分级，头一级长度为4
 * 
 * 
 * @author zgw 2009-7-15 上午02:05:53 javazgw@gmail.com
 */
public class MainPage extends LayoutContainer {

	GroupingStore<ModelData> leftstore = null;
	BaseStore<BaseModelData> imagestore = null;

	static LayoutContainer centerpanel = new LayoutContainer();
	static LayoutContainer centerpanel2 = new LayoutContainer(); //中间的排行第二
	static LayoutContainer centerpanel3 = new LayoutContainer();//中间的排行第三
	
	static LayoutContainer leftpanel2 = new LayoutContainer(); //左边的排行第二
	static LayoutContainer leftpanel3 = new LayoutContainer();//左边的排行第三
	static LayoutContainer rightpanel = new LayoutContainer();
	static LayoutContainer rightpanel2 = new LayoutContainer();//右边的排行第二
	static LayoutContainer rightpanel3 = new LayoutContainer();//右边的排行第三
	static LayoutContainer toppanel = new LayoutContainer();
	static LayoutContainer toppanelleft = new LayoutContainer();
	static LayoutContainer toppanelright = new LayoutContainer();
	static LayoutContainer logo = new LayoutContainer();
	static MainPage mainpage = null;
	BaseImageList bil = null;
	OneProduct oneproduct = null;
	static Button shoppingcar = new Button("查看购物车");
	
	final	HorizontalPanel hp = new HorizontalPanel();
	BaseStoreListener bsl = new BaseStoreListener(){
		@Override
		public void BaseStoreEventHandle(BaseStoreEvent evt) {
			// TODO Auto-generated method stub
			hp.removeAll();
			StoreInfo info  = imagestore.getStoreinfo();
			int rowcount =Integer.parseInt(imagestore.getTotlerowcount());//商品总数
			final int limit = Integer.parseInt(info.getLimit());//一页显示商品数量
			int pagecount = rowcount/limit + ((rowcount%limit)==0?0:1);
			//System.out.println(rowcount/limit);
			//System.out.println((rowcount%limit)==0?0:1);
		//	System.out.println(pagecount);
			Html h = new Html("页数：");
			hp.add(h);
			for(int i=0;i<pagecount;i++)
			{
				Button b = new Button((i+1)+"");
				final int row = i;
				b.addSelectionListener(new SelectionListener<ButtonEvent>(){

					@Override
					public void componentSelected(ButtonEvent ce) {
						// TODO Auto-generated method stub
						
						imagestore.getStoreinfo().setStart((row*limit)+"");
						imagestore.reload();
					}
					
				});
				hp.add(b);
			}
			bil.add(hp);
			bil.layout();
			//System.out.println("-----------------------------------");
		}
		@Override
		public void onBrowserEvent(Event event) {
			// TODO Auto-generated method stub
			
		}
	};
	public MainPage() {
		mainpage = this;
		init();

	}

	void init() {

		HtmlCommandFactory.InitatSetup(); //设置javascript函数
		htmladdtoshopcar(); //设置加入购物车的函数
		CreateImageStore();
		// bil = CreateGcode();

		TableLayout tl = new TableLayout(4);
		tl.setCellVerticalAlign(VerticalAlignment.TOP);
		this.setLayout(tl);
		TableData td = new TableData();
		td.setColspan(1);
		td.setRowspan(1);
		TableData td2 = new TableData();
		td2.setColspan(1);
		td2.setRowspan(2);
		TableData tdtop = new TableData();
		tdtop.setColspan(4);
		tdtop.setRowspan(1);
		tdtop.setHorizontalAlign(HorizontalAlignment.RIGHT);
		
		TableData tdtoplogo = new TableData();
		tdtoplogo.setColspan(4);
		tdtoplogo.setRowspan(1);
		tdtoplogo.setHorizontalAlign(HorizontalAlignment.LEFT);
	
		logo.setHeight("20px");
		logo.setLayout(new TableLayout(5));
		TableData tdlogo = new TableData();
		tdlogo.setRowspan(1);
		tdlogo.setColspan(1);
		tdlogo.setHorizontalAlign(HorizontalAlignment.LEFT);
		TableData tdlogo2 = new TableData();
		tdlogo2.setRowspan(1);
		tdlogo2.setColspan(4);
		
		Html h = new Html("<img src='images\\b2cimages\\logo.jpg'>");
		Html h2 = new Html("<img src='images\\b2cimages\\banner.gif'>");
		logo.add(h,tdlogo);
		logo.add(h2,tdlogo2);
		this.add(logo, tdtoplogo);
		

		CreateTop();
		this.add(toppanel, tdtop);
		
		
		VerticalPanel vpleft = new VerticalPanel();
		
		vpleft.add(CreateLeftGrid());
		vpleft.add(leftpanel2);
		vpleft.add(leftpanel3);
		this.add(vpleft, td);

		// centerpanel=bil;
		// CreateProductGroup();
		// Button b =new Button() ;//CreateProductGroup();
		//centerpanel.add(CreateProductGroup());
		//centerpanel.add(CreateProductGroup());
		
		VerticalPanel vpcenter = new VerticalPanel();
		centerpanel.add(CreateGcode());
//		
//		AutoDisplay adp = new AutoDisplay();
//		centerpanel2.add(adp.Display());
		
		vpcenter.add(centerpanel2);
		vpcenter.add(centerpanel);
		vpcenter.add(centerpanel3);
		
		this.add(vpcenter, td2);
		
		VerticalPanel vp = new VerticalPanel();
		rightpanel.setWidth(100);
		rightpanel2.setWidth(100);
		rightpanel3.setWidth(100);
		vp.add(rightpanel);
		vp.add(rightpanel2);
		vp.add(rightpanel3);
		
		RecommendGcode r = RecommendGcode.getinstance();
		r.setGcode(null);

		rightpanel.removeAll();
	
		rightpanel.add(r.showRecommendGcode());
		rightpanel.layout();
		
		
		B2cgcodeYouSaw.getinstance();
		this.add(vp, td);
		// this.add(centerpanel,td2);
	//	this.add(CreateTestGrid(), td);
		
	}
	
	private void CreateTop()
	{
		toppanel.setHeight("20px");
		toppanel.setAutoWidth(true);
		toppanel.setStyleName("x-layout-popup");
		toppanelleft.setWidth(600);
		toppanelright.setWidth(360);
		toppanelleft.setHeight("20px");
		toppanelright.setHeight("20px");
		toppanel.setLayout(new TableLayout(2));
		TableData td1 = new TableData();
		TableData td2 = new TableData();
		
		toppanel.add(toppanelleft,td1);
		toppanel.add(toppanelright,td2);
		CreateTopPanel();
	}
	private Widget CreateTestGrid()
	{
		
		 BaseGridView view = new BaseGridView();  
		 
		 ContentPanel panel = new ContentPanel();
			CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
			List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
			columns.add(cbs.getColumn());
			ColumnConfig gcode = new ColumnConfig("gcode", "商品分类", 100);
			TextField<String> gcodetext = new TextField<String>();
			gcode.setEditor(new CellEditor(gcodetext));
			columns.add(gcode);
			
			ColumnConfig qty = new ColumnConfig("qty", "商品数量", 100);
			TextField<String> qtytext = new TextField<String>();
			qty.setEditor(new CellEditor(qtytext));
			columns.add(qty);
			
			ColumnConfig qtyunit = new ColumnConfig("qtyunit", "商品数量单位", 100);
			TextField<String> qtyunittext = new TextField<String>();
			qtyunit.setEditor(new CellEditor(qtyunittext));
			columns.add(qtyunit);
			
			ColumnConfig discount = new ColumnConfig("discount", "折扣比例", 100);
			TextField<String> discounttext = new TextField<String>();
			discount.setEditor(new CellEditor(discounttext));
			columns.add(discount);
		
	
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");

			type.addField("gcode");
			type.addField("qty");
			type.addField("qtyunit");
			type.addField("discount");

			

			StoreInfo info = new StoreInfo();

			info.setTablename("b2cgcodeattr");
			
			info.setSql("select gcode,qty,qtyunit,discount from b2cgcodeattr");
		//	info.setParent(gcodestore);// 关联主表
			info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
			//info.setLinkparentcolumns(new String[] { "gcode" }); // 关联主表字段
			info.setKeyname(new String[] { "gcode", "idx" });
			BaseStore<JDBCModelData> gcodeattr = new BaseStore<JDBCModelData>(type, info);
//			gudong.setName("gudong");
//			gudong.setKeyname(new String[] { "ccode", "idx" }); // 主键
			ColumnModel cm = new ColumnModel(columns);
			BaseGrid attrgrid = new BaseGrid(gcodeattr, cm);
			attrgrid.setView(view);
			
			cbs.setSelectionMode(SelectionMode.SINGLE);

			attrgrid.setSelectionModel(cbs);
			attrgrid.setAutoHeight(true);
			//attrgrid.setAutoWidth(true);

			//registerStore(gcodeattr);
			attrgrid.setAutoHeight(true);
			panel.add(attrgrid);
		
			panel.setScrollMode(Scroll.AUTO);
			return panel;
		
	}

	public static LayoutContainer getToppanel() {
		return toppanel;
	}

	public static void setToppanel(LayoutContainer toppanel) {
		MainPage.toppanel = toppanel;
	}

	public static LayoutContainer getCenterpanel() {
		return centerpanel;
	}

	public static void setCenterpanel(LayoutContainer centerpanel) {
		MainPage.centerpanel = centerpanel;
	}

	public static LayoutContainer getRightpanel() {

		//rightpanel.setWidth(100);
		return rightpanel;
	}

	public static void setRightpanel(LayoutContainer rightpanel) {
		MainPage.rightpanel = rightpanel;
	}

	public static LayoutContainer getCenterpanel2() {
		return centerpanel2;
	}

	public static void setCenterpanel2(LayoutContainer centerpanel2) {
		MainPage.centerpanel2 = centerpanel2;
	}

	public static LayoutContainer getCenterpanel3() {
		return centerpanel3;
	}

	public static void setCenterpanel3(LayoutContainer centerpanel3) {
		MainPage.centerpanel3 = centerpanel3;
	}

	public static LayoutContainer getLeftpanel2() {
		return leftpanel2;
	}

	public static void setLeftpanel2(LayoutContainer leftpanel2) {
		MainPage.leftpanel2 = leftpanel2;
	}

	public static LayoutContainer getLeftpanel3() {
		return leftpanel3;
	}

	public static void setLeftpanel3(LayoutContainer leftpanel3) {
		MainPage.leftpanel3 = leftpanel3;
	}

	public static LayoutContainer getRightpanel2() {
		return rightpanel2;
	}

	public static void setRightpanel2(LayoutContainer rightpanel2) {
		MainPage.rightpanel2 = rightpanel2;
	}

	public static LayoutContainer getRightpanel3() {
		return rightpanel3;
	}

	public static void setRightpanel3(LayoutContainer rightpanel3) {
		MainPage.rightpanel3 = rightpanel3;
	}

	public static Button getShoppingcar() {
		
		return shoppingcar;
	}

	public static void setShoppingcar(Button shoppingcar) {
		MainPage.shoppingcar = shoppingcar;
	}

	public static void CreateTopPanel() {
		toppanelright.removeAll();
		
		
		Button login = new Button("登录");
		login.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				B2cLogin b2clogin = new B2cLogin();

				// Dialog dialog = new Dialog();
				b2clogin.CreateLoginDialog().show();

			}
		});
		toppanelright.add(login);
		toppanelright.layout();
	}

	Grid CreateLeftGrid() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

		ColumnConfig gname = new ColumnConfig("groupcolumn", "商品名称", 100);
		TextField<String> gnametext = new TextField<String>();
		gname.setEditor(new CellEditor(gnametext));
		columns.add(gname);
		ColumnConfig treename = new ColumnConfig("treename", "商品名称", 100);
		TextField<String> treenametext = new TextField<String>();
		treename.setEditor(new CellEditor(treenametext));
		columns.add(treename);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("treecode");
		type.addField("treename");
		type.addField("groupcolumn");

		StoreInfo info = new StoreInfo();

		info.setTablename("b2cgcodetree");
		info.setKeyname(new String[] { "b2cgcodetree" });
		// 注意商品分级，头一级长度为4
		info
				.setSql("select treecode,treename ,(select treename from b2cgcodetree as b where treecode=left(a.treecode,4)) as groupcolumn  from b2cgcodetree   as a where len(treecode)!=4 order by treename");
		// info.setParent(store);// 关联主表
		// info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
		// info.setLinkparentcolumns(new String[] { "ccode" }); // 关联主表字段

		BasePagingLoader loder = getBaseLoader(type, info);
		leftstore = new GroupingStore<ModelData>(loder);
		loder.load();
		leftstore.groupBy("groupcolumn");
		// leftstore = new BaseStore<JDBCModelData>(type, info);
		final ColumnModel cm = new ColumnModel(columns);
		final Grid b2cgcodegrid = new Grid(leftstore, cm);

		GroupingView view = new GroupingView();
		view.setShowGroupedColumn(false);
		view.setForceFit(true);
		view.setGroupRenderer(new GridGroupRenderer() {
			public String render(GroupColumnData data) {
				String f = cm.getColumnById(data.field).getHeader();
				String l = data.models.size() == 1 ? "条" : "条";
				return data.group + " (" + data.models.size() + " " + l + ")";
			}
		});
		b2cgcodegrid.setView(view);
		b2cgcodegrid.setAutoHeight(true);
		b2cgcodegrid.setAutoWidth(true);
		b2cgcodegrid.setHideHeaders(true);

		b2cgcodegrid.addListener(Events.OnClick, new Listener<GridEvent>() {

			@Override
			public void handleEvent(GridEvent be) {
				// TODO Auto-generated method stub
				// System.out.println(be.getRowIndex()+""+b2cgcodegrid.getSelectionModel().getSelectedItem().get("treecode"));
				// if(be.getType()==Events.SelectionChange)
				{

					if (leftstore != null) {

						imagestore.getStoreinfo().setFilter(
								" where treecode='"
										+ b2cgcodegrid.getSelectionModel()
												.getSelectedItem().get(
														"treecode") + "'");
						imagestore.reload();

						centerpanel.removeAll();
						// CreateGcode();
						//CreateProductGroup();
						// centerpanel.add(bil);
						centerpanel.add(CreateGcode());
						centerpanel.layout();

						RecommendGcode r = RecommendGcode.getinstance();
						r.setGcode(b2cgcodegrid.getSelectionModel()
								.getSelectedItem().get("treecode").toString());

						rightpanel.removeAll();
					
						rightpanel.add(r.showRecommendGcode());
						rightpanel.layout();

					}
				}
			}

		});
	//	b2cgcodegrid.setWidth("200px");
		return b2cgcodegrid;
	}

	void CreateImageStore() {

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("b2cgcode");
		type.addField("b2cgname");
		type.addField("gcode");
		type.addField("gname");
		type.addField("imagepath");
		type.addField("detailimageidx");
		type.addField("treecode");
		type.addField("price");
		type.addField("discountprice");

		StoreInfo info = new StoreInfo();
		info.setTablename("b2cgcode");
		info
				.setSql("select b2cgcode,b2cgname,gcode,gname,(select top 1 imagepath from b2cgcodeimage where b2cgcodeimage.b2cgcode = b2cgcode.b2cgcode)  as imagepath,detailimageidx,treecode,price,discountprice from b2cgcode ");
		info.setStart("0");
		info.setLimit("18");
		info.setSortcolumn("adddate");
		imagestore = new BaseStore<BaseModelData>(type, info);
		imagestore.setName("b2cgcode");

		imagestore.setLinkparentcolumns(new String[] { "treecode" });
	}

	LayoutContainer CreateProductGroup() {
		final LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(2);
		lc.setLayout(tl);
		final TableData td = new TableData();
		td.setRowspan(1);
		td.setColspan(1);

		imagestore.addBaseStoreListener(EventType.LOAD_COMPLETE,
				new BaseStoreListener() {

					@Override
					public void BaseStoreEventHandle(BaseStoreEvent evt) {
						// TODO Auto-generated method stub
						final int size = imagestore.getModels().size();
						// System.out.println("size="+size);
						//System.out.println("----------"+imagestore.getCount());
						Timer timer = new Timer() {
							int i = 0;

							@Override
							public void run() {
								// TODO Auto-generated method stub

								// for(int i=0;i<size;i++)
								{
									String b2cgcode = imagestore.getValue(i,
											"b2cgcode").toString();
									ProdectDesc p = new ProdectDesc(b2cgcode);
									p.setPrice("100");
									p.setName("zgw");

						
									p.setMainimagepath(imagestore.getValue(i,
											"imagepath").toString());
									ImageGroup ii = new ImageGroup();

									DetailDesc detaildesc = new DetailDesc();
							
									p.put("button", ii);
									p.put("detaildesc", detaildesc);
									OneProductMin om = new OneProductMin(p);

									lc.add(om, td);
								}
								i++;

								lc.layout();
								if (i >= size) {

									this.cancel();

								}
							}

						};
						// timer.schedule(10);
						timer.scheduleRepeating(1);
					
						timer.run();

					}

					@Override
					public void onBrowserEvent(Event event) {
						// TODO Auto-generated method stub

					}

				});
		return lc;

	}

	/**
	 * 商品信息，根据大类换行,
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public BaseImageList CreateGcode() {
		
	

		bil = new BaseImageList(imagestore, null, false) {

			protected native String getTemplate() /*-{
		var r= ['<table width="50" border="1"><tpl  for=".">', 
		
		'<tpl if="xindex %4 ==1">',
		'<tr>',
		'</tpl>',
		'<td>',
		'<div class=x-view-item>',
		'<div class="thumb-wrap"  id="{name}" style="border: 1px solid white;width:100px;height:140px">', 

		'<div class="thumb" style="float:top;width:100px;height:140px" ><img  style="width:100px;height:100px;margin: 3px 3px 3px 3px"  src="{imagepath}" title="{b2cgname}{#}"></div>', 
		

		'<span class="x-editable">{b2cgname}</span></div>', 
		
		'</div>',
		'<td>',
		'<tpl if="xindex %4 ==0">',
		'</tr>',
		'</tpl>',
		'</tpl></table>',
		'<div class="x-clear"></div>'].join(""); 

		//return r;
			var r2= ['<tpl  for=".">', 
			'<div>',
		'<div style="font-family: tahoma, arial, helvetica, sans-serif;  font-size: 12px;  font-size-adjust: none;  font-stretch: normal;font-style: normal;font-variant: normal;font-weight: normal;line-height: normal;overflow: hidden;white-space: nowrap;">',
		'<a href="www.163.com">e</a>',
		'<div class="thumb-wrap"  id="{name}" style="border: 1px solid white;width:100px;height:140px;float:left;margin: 10px 10px 10px 10px">', 

		'<div class="thumb"  style="float:top"><img style="width:100px;height:100px;margin: 3px 3px 3px 3px" src="{imagepath}" title="{b2cgname}"></div>', 
		

		'<span class="x-editable">{b2cgname}</span><a>aa</a></div>', 
		'</div>',
		'</div>',
		'</tpl>',
		'<div class="x-clear"></div>'].join(""); 

		//return r2;
		
				var r3= ['<table width="50" border="0px"><tpl  for=".">', 
					'<tpl if="xindex %4 ==1">',
		'<tr>',
		'</tpl>',
		'<td >',
			'<div style="border: 0px solid white;width:150px;height:140px;float:left">',
			
		'<div style="border: 0px solid white;width:110px;height:140px;float:left;margin: 10px 10px 10px 10px;font-family: tahoma, arial, helvetica, sans-serif;  font-size: 12px;  font-size-adjust: none;  font-stretch: normal;font-style: normal;font-variant: normal;font-weight: normal;line-height: normal;overflow: hidden;white-space: nowrap;">',
	
		'<div class="thumb-wrap"  id="{name}" style="border: 0px solid white;width:100px;height:140px;float:left">', 

		'<div class="thumb"  style="float:left"><img style="width:100px;height:100px;margin: 3px 3px 3px 3px" src="{imagepath}" title="{b2cgname}"></div>', 
		

		'<span class="x-editable"></span>', 
			
		'</div>',
	
		'</div>',
		'<a href="javascript:void(0)" onclick=\"javascript:itemaddtoshopingcar({b2cgcode})\" style="table-layout:fixed;word-break:break-all"><img src =\"images/b2cimages/shoppingcar.gif\" /></a>',
	
		'{b2cgname}',
		 '<tpl if="typeof(discountprice)!=&quot;undefined&quot;">',
	 '<p><a>原价:</a><a style="text-decoration:line-through">{price}</a><p><a>折扣价:{discountprice}</a>',
	 '</tpl>',
	 	 '<tpl if="typeof(discountprice)==&quot;undefined&quot;">',
	 '<p><a>原价:{price}</a>',
	
	 '</tpl>',
	 
		'</div>',
		'<td>',
		'<tpl if="xindex %4 ==0">',
		'</tr>',
		'</tpl>',
		'</tpl></table>',
		
		'<div class="x-clear"><hr /></div>'].join(""); 
		return r3;
//	     return ['<tpl for=".">', 
//     '<div class="thumb-wrap" id="{name}" style="border: 1px solid white;float:left;float: left;width:300px;height:200px;margin: 5px 5px 5px 5px">', 
//     '<div class="thumb"><img   src="busiimages/20090714/playing_beach.jpg" title="{dd}"></div>', 
//     '<span class="x-editable">{dd}</span></div>', 
//     '</tpl>', 
//     '<div class="x-clear"></div>'].join(""); 
//      

		//     return '<img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" title="{name}"><img src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" title="{name}">';
	}-*/;
		};
	
		
		imagestore.removeBaseStoreListener(EventType.LOAD_COMPLETE, bsl);
		//imagestore.removeBaseStoreListener(EventType.LOAD_COMPLETE);
		imagestore.addBaseStoreListener(EventType.LOAD_COMPLETE,
				bsl);
		bil.getView().getSelectionModel().addSelectionChangedListener(
				new SelectionChangedListener() {

					@Override
					public void selectionChanged(SelectionChangedEvent se) {
						// TODO Auto-generated method stub
						if (se.getSelection().size() > 0) {
						
							AttrFactory af = new AttrFactory(((BaseModelData)se.getSelection().get(0)).get("b2cgcode").toString());
							af.initAttrShow();
							oneproduct = new OneProduct(af.getP());
							


				
							centerpanel.removeAll();
				
							centerpanel.add(oneproduct);
				

							centerpanel.layout();
					
			
						}

					}

				});
		bil.setWidth(720);
		
		
		
		// centerpanel.setHeaderVisible(false);
		return bil;

	}

	
	ContentPanel CreateB2cGcodeDetail() {
		ContentPanel panel = new ContentPanel();

		panel.setAutoWidth(true);
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig gcode = new ColumnConfig("gcode", "商品分类编码", 100);
		TextField<String> gcodetext = new TextField<String>();
		gcode.setEditor(new CellEditor(gcodetext));
		columns.add(gcode);
		ColumnConfig gname = new ColumnConfig("gname", "商品分类名称", 100);
		TextField<String> gnametext = new TextField<String>();
		gname.setEditor(new CellEditor(gnametext));
		columns.add(gname);

		ColumnConfig treecode = new ColumnConfig("treecode", "商品分类树", 100);

		ModelType combotype = new ModelType();
		combotype.setRoot("records");
		combotype.setRecordName("record");
		combotype.setTotalName("totle");
		combotype.addField("code", "ccode");
		combotype.addField("name", "cname");
		StoreInfo comboinfo = new StoreInfo();

		comboinfo.setTablename("ccode");
		comboinfo.setSql("select * from ccode");
		BaseComboBox combo = new BaseComboBox(combotype, comboinfo);
		// combo.setDisplayField("name");
		// combo.setValueField("value");
		BaseCellEditorCB editor = new BaseCellEditorCB(combo,"code","name");

		treecode.setEditor(editor);

		treecode.setRenderer(editor);

		columns.add(treecode);

		ColumnConfig b2cgcodecolumn = new ColumnConfig("b2cgcode", "商品分类编码",
				100);
		TextField<String> b2cgcodetext = new TextField<String>();
		b2cgcodecolumn.setEditor(new CellEditor(b2cgcodetext));
		columns.add(b2cgcodecolumn);
		ColumnConfig b2cgname = new ColumnConfig("b2cgname", "商品分类名称", 100);
		TextField<String> b2cgnametext = new TextField<String>();
		b2cgname.setEditor(new CellEditor(b2cgnametext));
		columns.add(b2cgname);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("gcode");
		type.addField("gname");
		type.addField("b2cgcode");
		type.addField("b2cgname");
		type.addField("mainimagepath");
		type.addField("treecode");
		type.addField("detailimage");

		StoreInfo info = new StoreInfo();

		info.setTablename("b2cgcode");
		info.setKeyname(new String[] { "b2cgcode" });
		info.setSql("select * from b2cgcode");
		// info.setParent(store);// 关联主表
		// info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
		// info.setLinkparentcolumns(new String[] { "ccode" }); // 关联主表字段
		BaseStore<JDBCModelData> b2cgcode = new BaseStore<JDBCModelData>(type,
				info);
		// gudong.setName("gudong");
		// gudong.setKeyname(new String[] { "ccode", "idx" }); // 主键
		ColumnModel cm = new ColumnModel(columns);
		BaseGrid b2cgcodegrid = new BaseGrid(b2cgcode, cm);

		// BaseGridView view = new BaseGridView();
		// b2cgcodegrid.setView(view);
		cbs.setSelectionMode(SelectionMode.SINGLE);

		b2cgcodegrid.setSelectionModel(cbs);
		b2cgcodegrid.setAutoHeight(true);
		b2cgcodegrid.setAutoWidth(true);

		// registerStore(b2cgcode);
		panel.add(b2cgcodegrid);
		panel.setScrollMode(Scroll.AUTO);
		return panel;
	}

	public BasePagingLoader<PagingLoadResult<JDBCModelData>> getBaseLoader(
			final ModelType type, StoreInfo storeinfo) {
		Date date = new Date();
		RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL
				.encode("BaseServlet?Action=Loaddata" + "&"
						+ storeinfo.getStoreInfoString()));
		builder.setHeader("Content-Type",
				"application/x-www-form-urlencoded;charset=utf-8");

		builder.setCallback(new RequestCallback() {

			@Override
			public void onError(Request request, Throwable exception) {
				// TODO Auto-generated method stub
				// System.out.println("error.....");
			}

			@Override
			public void onResponseReceived(Request request, Response response) {
				// 

			}
		});
		HttpProxy proxy = new HttpProxy(builder);

		// need a loader, proxy, and reader
		XmlReader reader = new XmlReader(type) {

			protected ListLoadResult newLoadResult(Object loadConfig,
					List models) {
				PagingLoadConfig pagingConfig = (PagingLoadConfig) loadConfig;
				PagingLoadResult<ModelData> result = new BasePagingLoadResult<ModelData>(
						models, pagingConfig.getOffset(), pagingConfig
								.getLimit());

				return result;
			}

			@Override
			public ListLoadResult read(Object loadConfig, Object data) {
				Document doc = XMLParser.parse((String) data);

				NodeList list = doc.getElementsByTagName(type.getRecordName());
				ArrayList<ModelData> records = new ArrayList<ModelData>();
				for (int i = 0; i < list.getLength(); i++) {
					Node node = list.item(i);
					Element elem = (Element) node;
					ModelData model = newModelInstance();
					for (int j = 0; j < type.getFieldCount(); j++) {
						DataField field = type.getField(j);
						String map = field.getMap() != null ? field.getMap()
								: field.getName();
						String v = getValue(elem, map);
						model.set(field.getName(), v);
					}
					records.add(model);
				}

				int totalCount = records.size();

				Node root = doc.getElementsByTagName(type.getRoot()).item(0);
				if (root != null && type.getTotalName() != null) {
					Node totalNode = root.getAttributes().getNamedItem(
							type.getTotalName());
					if (totalNode != null) {
						String sTot = totalNode.getNodeValue();
						totalCount = Integer.parseInt(sTot);
					}
				}
				// 获得自曾字段的值

				/*
				 * if (root != null ) { Node totalNode =
				 * root.getAttributes().getNamedItem("autoinc"); if (totalNode
				 * != null) { autoinc = totalNode.getNodeValue();
				 * System.out.println("----------z "+autoinc); } }
				 */
				ListLoadResult result = newLoadResult(loadConfig, records);
				if (result instanceof PagingLoadResult) {
					PagingLoadResult r = (PagingLoadResult) result;
					r.setTotalLength(totalCount);
				}
				return result;
			}

		};
		BasePagingLoader<PagingLoadResult<JDBCModelData>> loader = new BasePagingLoader<PagingLoadResult<JDBCModelData>>(
				proxy, reader);

		return loader;
	}
	public static native void htmladdtoshopcar() /*-{
	$wnd.itemaddtoshopingcar = function(id){
	
		
			
		@com.base.myproject.client.busi.b2c.MainPage::add2car(Ljava/lang/String;)(""+id+"");
	
	}
	
}-*/;
	public static void add2car(String id)
	{
		ShoppingCar shoppingcar = new ShoppingCar();
		shoppingcar.add2Car(id);
		
	}

	/**
	 * @return the mainpage
	 */
	public static MainPage getMainpage() {
		return mainpage;
	}

	/**
	 * @param mainpage the mainpage to set
	 */
	public static void setMainpage(MainPage mainpage) {
		MainPage.mainpage = mainpage;
	}

	/**
	 * @return the toppanelleft
	 */
	public static LayoutContainer getToppanelleft() {
		return toppanelleft;
	}

	/**
	 * @param toppanelleft the toppanelleft to set
	 */
	public static void setToppanelleft(LayoutContainer toppanelleft) {
		MainPage.toppanelleft = toppanelleft;
	}

	/**
	 * @return the toppanelright
	 */
	public static LayoutContainer getToppanelright() {
		return toppanelright;
	}

	/**
	 * @param toppanelright the toppanelright to set
	 */
	public static void setToppanelright(LayoutContainer toppanelright) {
		MainPage.toppanelright = toppanelright;
	}

	/**
	 * @return the imagestore
	 */
	public BaseStore<BaseModelData> getImagestore() {
		return imagestore;
	}

	/**
	 * @param imagestore the imagestore to set
	 */
	public void setImagestore(BaseStore<BaseModelData> imagestore) {
		this.imagestore = imagestore;
	}

	
}
